import os

from celery import Celery
from celery.schedules import crontab
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fakebo.settings')

app = Celery('fakebo')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# 此处是在添加定时任务，task的值要从worker发现的task列表中选取。
app.conf.update(
    CELERYBEAT_SCHEDULE={
        # 'add1':{
        #     'task':'server.tasks.add',
        #     'schedule':crontab(minute='*/2'),
        #     'args': (1, 2)
        # },
        # 'add2':{
        #     'task':'server.tasks.add',
        #     'schedule':crontab(minute='*/3'),
        #     'args': (3, 2)
        # },
        'sync_article_thumbups':{
            'task':'server.tasks.sync_thumbup',
            'schedule':crontab(minute='*'),
            'args': ('Article',)
        },
        'sync_comment_thumbups':{
            'task':'server.tasks.sync_thumbup',
            'schedule':crontab(minute='*'),
            'args': ('Comment',)
        }
    }
)

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()